package com.breez.shorturl.controller;


import com.breez.shorturl.controller.base.BaseController;
import com.breez.shorturl.entity.ShortInfo;
import com.breez.shorturl.entity.request.ShortInfoForm;
import com.breez.shorturl.entity.request.UrlSearchForm;
import com.breez.shorturl.service.IShortInfoService;
import com.breez.shorturl.util.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author BreezAm
 * @since 2021-12-13
 */
@Api(tags = "短网址操作接口")
@RestController
@RequestMapping("/api/shorturl/shortInfo")
public class ShortInfoController extends BaseController {
    private final Logger logger = LoggerFactory.getLogger(ShortInfoController.class);
    @Autowired
    private IShortInfoService shortInfoService;

    @ApiOperation("生成短网址")
    @PostMapping("addShortInfo")
    public R addShortInfo(@RequestBody @Validated ShortInfoForm shortInfoForm) {
        shortInfoService.addShortInfo(shortInfoForm);
        return R.ok();
    }

    @ApiOperation("更新短网址")
    @PutMapping("update")
    public R updateShortInfo() {
        return null;
    }

    @ApiOperation("删除短网址")
    @DeleteMapping("delete")
    public R deleteShortInfo() {
        return null;
    }

    @ApiOperation("获取短网址信息")
    @GetMapping("getShortInfo")
    public R getShortInfo() {

        return null;
    }

    @ApiOperation("获取所有的短网址")
    @PostMapping("shortInfoList")
    public R shortShortInfoList(@RequestBody(required = false) UrlSearchForm urlSearchForm) {
        logger.info("短链接搜索参数：{}", urlSearchForm);
        List<ShortInfo> data = shortInfoService.listByParams(urlSearchForm);
        return R.ok(data);
    }

}
